package com.hzjq.fxlib.adapter

import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.hzjq.core.bean.ErrorCapEntity
import com.hzjq.fxlib.R

class RegisterAdapter : BaseQuickAdapter<ErrorCapEntity, BaseViewHolder> {

    constructor(data: MutableList<ErrorCapEntity>?) : super(R.layout.item_register_cap_layout, data)

    override fun convert(holder: BaseViewHolder, item: ErrorCapEntity) {
        holder.setText(
            R.id.registerItemLocationText,
            "${item.cap!!.rowNumber}-${item.cap!!.holeNumber}"
        )

        holder.setText(R.id.registerItemUidText,item.cap!!.convertUid)

        holder.setText(R.id.registerItemDelayText, item.cap!!.delay.toString())
        if (item.errorCode == 0) {
            holder.setText(R.id.registerItemStateText, "正常")
            holder.setTextColor(
                R.id.registerItemStateText,
                ContextCompat.getColor(context, R.color.text_gray_color)
            )
        } else if (item.errorCode == -1) {
            holder.setText(R.id.registerItemStateText, "爆破完成")
            holder.setTextColor(
                R.id.registerItemStateText,
                ContextCompat.getColor(context, android.R.color.holo_green_light)
            )
        } else {
            holder.setText(R.id.registerItemStateText, item.error)
            holder.setTextColor(
                R.id.registerItemStateText,
                ContextCompat.getColor(context, android.R.color.holo_red_light)
            )
        }
    }
}